# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=libdeflate
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8
pkgrel=2
pkgdesc="Heavily optimized library for DEFLATE/zlib/gzip compression and decompression (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/ebiggers/libdeflate'
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/v${pkgver}.tar.gz"
        "001-libdeflate-makefile-mingw-fix.patch")
sha256sums=('50711ad4e9d3862f8dfb11b97eb53631a86ee3ce49c0e68ec2b6d059a9662f61'
            '0c6104d036417f12b969fd36b821cca11da29b61a26caa179cfdfe39fb4b57c8')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-libdeflate-makefile-mingw-fix.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -a "${srcdir}"/${_realname}-${pkgver} "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  make PREFIX=${MINGW_PREFIX}
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install PREFIX=${MINGW_PREFIX} DESTDIR="${pkgdir}"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
